﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">

    <xsl:import href="param.add.xsl"/>

    <xsl:template name="footer.content">
        <xsl:param name="pageclass" select="''"/>
        <xsl:param name="sequence" select="''"/>
        <xsl:param name="position" select="''"/>
        <xsl:param name="gentext-key" select="''"/>
        <fo:block>
            <xsl:choose>
                <xsl:when
                    test="$pageclass = 'titlepage' or (/article and $pageclass = 'body' and $sequence = 'first')"/>
                <xsl:when test="$double.sided != 0 and $sequence = 'even' and $position = 'center'">
                    <xsl:call-template name="custom.footer.content">
                        <xsl:with-param name="image" select="$doc.header-bitmap.left"/>
                        <xsl:with-param name="text-indent">
                            <xsl:text>25mm</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="align">
                            <xsl:text>left</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when
                    test="$double.sided != 0 and ($sequence = 'odd' or $sequence = 'first') and $position='center'">
                    <xsl:call-template name="custom.footer.content">
                        <xsl:with-param name="image" select="$doc.header-bitmap.right"/>
                        <xsl:with-param name="text-indent">
                            <xsl:text>25mm</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="align">
                            <xsl:text>right</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="$double.sided = 0 and $position='center'">
                    <xsl:call-template name="custom.footer.content">
                        <xsl:with-param name="image" select="$doc.header-bitmap.left"/>
                        <xsl:with-param name="text-indent">
                            <xsl:text>25mm</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="align">
                            <xsl:text>left</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="$sequence='blank'">
                    <xsl:choose>
                        <xsl:when test="$double.sided != 0 and $position = 'left'"/>
                        <xsl:when test="$double.sided = 0 and $position = 'center'"/>
                        <xsl:otherwise/>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise/>
            </xsl:choose>
        </fo:block>
    </xsl:template>

    <xsl:template name="foot.sep.rule">
        <xsl:if test="$footer.rule != 0">
            <xsl:attribute name="border-top-width">thin</xsl:attribute>
            <xsl:attribute name="border-top-style">solid</xsl:attribute>
            <xsl:attribute name="border-top-color">
                <xsl:value-of select="$title.font.color"/>
            </xsl:attribute>
        </xsl:if>
    </xsl:template>

    <xsl:template name="header.content">
        <xsl:param name="pageclass" select="''"/>
        <xsl:param name="sequence" select="''"/>
        <xsl:param name="position" select="''"/>
        <xsl:param name="gentext-key" select="''"/>
        <fo:block>
            <xsl:choose>
                <xsl:when
                    test="$sequence='even' and $position='center' and $pageclass != 'titlepage'">
                    <xsl:attribute name="start-indent">
                        <xsl:text>5px</xsl:text>
                    </xsl:attribute>
                    <xsl:call-template name="custom.header.content">
                        <xsl:with-param name="align">
                            <xsl:text>left</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="contents">
                            <xsl:choose>
                                <xsl:when test="ancestor::book and ($double.sided != 0)">
                                    <xsl:apply-templates select="." mode="object.title.markup"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:apply-templates select="." mode="titleabbrev.markup"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when
                    test="$sequence='even' and $position='right' and $pageclass != 'titlepage'">
                    <xsl:call-template name="custom.header.empty"/>
                </xsl:when>
                <xsl:when test="$sequence='odd' and $position='left' and $pageclass != 'titlepage'">
                    <xsl:call-template name="custom.header.empty"/>
                </xsl:when>
                <xsl:when
                    test="$sequence='odd' and $position='center' and $pageclass != 'titlepage'">
                    <xsl:attribute name="end-indent">
                        <xsl:text>5px</xsl:text>
                    </xsl:attribute>
                    <xsl:call-template name="custom.header.content">
                        <xsl:with-param name="align">
                            <xsl:text>right</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="contents">
                            <xsl:choose>
                                <xsl:when test="ancestor::book and ($double.sided != 0)">
                                    <xsl:apply-templates select="." mode="object.title.markup"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:apply-templates select="." mode="titleabbrev.markup"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when
                    test="$double.sided != 0 and $sequence = 'even' and $position='left' and $pageclass != 'titlepage'">
                    <xsl:call-template name="fo-page-number.square">
                        <xsl:with-param name="background-color" select="$title.font.color"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when
                    test="$double.sided != 0 and $sequence = 'odd' and $position='right' and $pageclass != 'titlepage'">
                    <!-- FIXME this makes all pages of an article look like odd pages from  a doubleseq -->
                    <xsl:call-template name="fo-page-number.square">
                        <xsl:with-param name="background-color" select="$title.font.color"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when
                    test="$double.sided = 0  and $sequence = 'odd' and $position='right' and $pageclass != 'titlepage'">
                    <xsl:call-template name="fo-page-number.square">
                        <xsl:with-param name="background-color" select="$title.font.color"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="$position='center'"/>
                <xsl:when test="$sequence = 'first'"/>
                <xsl:when test="$sequence = 'blank'"/>
                <xsl:otherwise/>
            </xsl:choose>
        </fo:block>
    </xsl:template>

    <xsl:template name="head.sep.rule">
        <xsl:if test="$header.rule != 0">
            <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
            <xsl:attribute name="border-bottom-style">solid</xsl:attribute>
            <xsl:attribute name="border-bottom-color">
                <xsl:value-of select="$title.font.color"/>
            </xsl:attribute>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>
